#include <iostream>
#include <cstring>
using namespace std;

/*
【题目205】假设图书馆的图书包含书名、编号和作者三个属性，读者包含姓名和借书证
属性，每位读者最多可借5本书，编写一个C++程序列出某读者的借书情况。
*/

class Object
{
public:
    Object()
    {
    }
    Object(string name, string id)
    {
        this->name = name;
        this->id = id;
    }

    string getName()
    {
        return name;
    }

    string getId()
    {
        return id;
    }

private:
    string name;
    string id;
};

class Book : public Object
{
public:
    Book(string name, string id, string author) : Object(name, id)
    {
        this->author = author;
    }

    void showBook()
    {
        cout << getName() << "\t" << getId() << "\t" << author << endl;
    }

private:
    string author;
};

class Reader : public Object
{
public:
    Reader(string name, string id) : Object(name, id)
    {
        memset(books, 0, sizeof(books));
        bookCount = 0;
    }

    void rentbook(Book *book)
    {
        if (bookCount >= 5)
        {
            cout << "您已借满5本书,不能再借书了" << endl;
            return;
        }

        for (int count = 0; count < 5; count++)
        {
            if (books[count] == NULL)
            {
                books[count] = book;
                bookCount++;
                cout << "用户[" << getName() << "] 借书成功! 书名: " << books[count]->getName() << endl;
                return;
            }
        }
    }

private:
    int bookCount; // 借书数量
    Book *books[5];
};

int main()
{

    Book **book = new Book *[6];
    memset(book, 0, sizeof(book));

    book[0] = new Book("C++", "123", "张三");
    book[1] = new Book("C", "124", "李四");
    book[2] = new Book("Java", "125", "王五");
    book[3] = new Book("Python", "126", "赵六");
    book[4] = new Book("PHP", "127", "钱七");
    book[5] = new Book("js", "128", "孙八");

    Reader *reader = new Reader("张三", "001");

    cout << "name\tid\tauthor" << endl;
    for (int i = 0; i < 6; i++)
    {
        book[i]->showBook();
    }
    for (int i = 0; i < 6; i++)
    {
        reader->rentbook(book[i]);
    }
}
